﻿//文件指定编译编码UTF-8
#pragma execution_character_set("utf-8")


#include "scanrulesavedialog.h"
#include "ui_scanrulesavedialog.h"
#include <QFileDialog>

ScanRuleSaveDialog::ScanRuleSaveDialog(ScanRule *object,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ScanRuleSaveDialog)
{
    ui->setupUi(this);
    objectInfo = object;
    if(objectInfo->getId() != 0){
        setWindowTitle("修改策略");
        ui->filterContent->setText(objectInfo->getFilterContent());
        ui->byFileName->setChecked(objectInfo->getByFileName());
        ui->byFileContent->setChecked(objectInfo->getByFileContent());
        ui->moveDir->setText(objectInfo->getMoveDir());
    }else{
        setWindowTitle("添加策略");
    }
}

ScanRuleSaveDialog::~ScanRuleSaveDialog()
{
    delete ui;
}

void ScanRuleSaveDialog::on_cancelBtn_clicked()
{
    QDialog::reject();
}

void ScanRuleSaveDialog::on_saveBtn_clicked()
{
    objectInfo->setFilterContent(ui->filterContent->text());
    objectInfo->setByFileName(ui->byFileName->isChecked());
    objectInfo->setByFileContent(ui->byFileContent->isChecked());
    objectInfo->setMoveDir(ui->moveDir->text());
    QDialog::accept();
}

void ScanRuleSaveDialog::on_selScanMoveDir_clicked()
{
    QString openDir=ui->moveDir->text();

    QString moveDir = QFileDialog::getExistingDirectory(this,QString("选择归档路径"),openDir);
    if(!moveDir.isEmpty()){
        ui->moveDir->setText(moveDir);
    }
}
